package com.controller.action.mango;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.controller.action.BaseAct;
import com.mangocity.airticket.b2b.webservice.LowPriceResponse;
import com.mangocity.airticket.b2b.webservice.LowPriceService;
import com.wrap.mango.lowprice.LowPriceRequest;
import com.wrap.mango.lowprice.LowPriceResult;

@Controller
public class LowPriceAct extends BaseAct {
    private final Log logger = LogFactory.getLog(getClass());
    
    @RequestMapping(value = "lowprice", method = RequestMethod.GET)
    public @ResponseBody LowPriceResult queryDefault(HttpServletRequest request) {
        return queryByParams(new LowPriceRequest());
    }
    
    @RequestMapping(value = "http/lowprice", method = RequestMethod.POST)
    public @ResponseBody LowPriceResult queryByParams(LowPriceRequest lowPriceRequest) {
        LowPriceResult lowPriceResult = new LowPriceResult();
        try {
            LowPriceService lowPriceService = mangoFacadeService.getLowPriceService();
            LowPriceResponse lowPriceResponse = lowPriceService.query(lowPriceRequest.convertLowPriceRequest());
            
            if (null != lowPriceResponse) {
                lowPriceResult = lowPriceResult.convertLowPriceResult(lowPriceResponse.getLowPriceResulst());
            }
        } catch (Exception e) {
            logger.error("query low price error", e);
        }
        return lowPriceResult;
    }

    @RequestMapping(value = "lowprice", method = RequestMethod.POST)
    public @ResponseBody LowPriceResult queryByParams2(@RequestBody LowPriceRequest lowPriceRequest) {
        LowPriceResult lowPriceResult = new LowPriceResult();
        try {
            LowPriceService lowPriceService = mangoFacadeService.getLowPriceService();
            LowPriceResponse lowPriceResponse = lowPriceService.query(lowPriceRequest.convertLowPriceRequest());
            
            if (null != lowPriceResponse) {
                lowPriceResult = lowPriceResult.convertLowPriceResult(lowPriceResponse.getLowPriceResulst());
            }
        } catch (Exception e) {
            logger.error("query low price error", e);
        }
        return lowPriceResult;
    }
    
}
